package com.cn.wanxi.servlet.company;

import com.alibaba.fastjson.JSONObject;
import com.cn.wanxi.model.CompanyModel;
import com.cn.wanxi.service.CompanyService;
import com.cn.wanxi.service.impl.CompanyServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/back/company/add")
public class CompanyAddServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //       1. 在这里需要拿到前端传递到后台的数据
        String logo = req.getParameter("logo");
        String phone = req.getParameter("phone");
        String net = req.getParameter("net");
        String address = req.getParameter("address");
        String version = req.getParameter("version");
        String linePhone = req.getParameter("linePhone");
        //       2. 封装到对象
        CompanyModel companyModel = new CompanyModel();
        companyModel.setVersion(version);
        //        3.调用服务逻辑层
        CompanyService companyService=new CompanyServiceImpl();
        //        4.接受返回数据
        String result=companyService.add(companyModel);
        //        5.返回给页面
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("result", result);
        resp.getWriter().println(jsonObject);
    }
}
